<?php

namespace IDock\Insurance\QHIC\Response;

use IDock\Http\Response;
use IDock\IDock\IDock;
use IDock\IDock\IDockEnums;
use IDock\Insurance\QHIC\Response\AllQHICResponse;
use IDock\Printer\ProposalStatusPrinter;

class ProposalStatusResponse extends AllQHICResponse
{

    /**
     * @var ProposalStatusPrinter $printer
     */
    public $printer = ProposalStatusPrinter::class;

    public function printerInit(): Response
    {
        $body = $this->getBody() ?? [];

        $list = $body['BaseList'] ?? [];
        $statusArr = [];
        foreach ($list as $value){
            $statusArr[] = $value['CAppStatus'] ?? '';
        }
        $status1 = $statusArr[0] ?? '1';
        $status2 = $statusArr[1] ?? '1';
        //核保通过
        if(count($statusArr) > 1){
            if ($status1 == '2' and $status2 == '2') {
                $this->printer->statusCode = 'U1';
            }
            //核保退回
            if ($status1 == '3' or $status2 == '3') {
                $this->printer->statusCode = 'U2';
            }

            //人工核保
            if (in_array($status1,['0','1']) or in_array($status2,['0','1'])) {
                $this->printer->statusCode = 'U3';
            }
        }else{
            if ($status1 == '2' ) {
                $this->printer->statusCode = 'U1';
            }
            //核保退回
            if ($status1 == '3') {
                $this->printer->statusCode = 'U2';
            }

            //人工核保
            if (in_array($status1,['0','1'])) {
                $this->printer->statusCode = 'U3';
            }
        }

        $this->printer->status = IDockEnums::$underStats[$this->printer->statusCode] ?? '';
        return $this;
    }
}
